package com.wtwd.campus.service.impl;


import com.wtwd.campus.dao.LbsDataMapper;
import com.wtwd.campus.entity.LbsData;
import com.wtwd.campus.entity.LocationInfo;
import com.wtwd.campus.model.dto.LbsDTO;
import com.wtwd.campus.service.LbsDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author mjy
 * @since 2024-08-19
 */
@Service
public class LbsDataServiceImpl implements LbsDataService {

    @Autowired
    private LbsDataMapper lbsDataMapper;

    /**
     * 筛选信号最强的
     *
     * @param lbsDatas
     * @return
     */
    @Override
    public LocationInfo getLocationByLBS(List<LbsDTO> lbsDatas) {
        if (lbsDatas == null || lbsDatas.size() == 0) return null;
        LbsDTO lbsDTO = lbsDatas.get(0);
        LbsData one = lbsDataMapper.selectByLbs(lbsDTO.getMcc(), lbsDTO.getMnc(), lbsDTO.getLac(), lbsDTO.getCid());
        if (one == null) {
            return null;
        }
        LocationInfo locationInfo = new LocationInfo();
        locationInfo.setLat(one.getLat());
        locationInfo.setLng(one.getLng());
        locationInfo.setLocationType(LocationInfo.LocationTypeEnum.LBS.getCode());
        return locationInfo;
    }

    @Override
    public boolean batchInsertOrUpdate(List<LbsData> lbsDatas) {
        if (lbsDatas == null || lbsDatas.size() == 0) {
            return false;
        }
        return lbsDataMapper.batchInsertOrUpdate(lbsDatas);
    }

}
